package com.zeno.soil.rbac.model.vo;

import com.zeno.soil.common.entity.BasePojo;
import com.zeno.soil.rbac.repository.po.Role;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 角色列表项
 * @author zeno
 */
@Data
public class RoleVO extends BasePojo{

  /**
   * 角色编码
   */
  private String code;

  /**
   * 角色名称
   */
  private String name;

  /**
   * 角色备注
   */
  private String remark;

  /**
   * 是否固定角色不可删除
   */
  private Integer fixed;

  public static RoleVO createFrom( Role role ){

    RoleVO roleItemVO = new RoleVO();
    roleItemVO.setCode(role.getCode());
    roleItemVO.setName(role.getName());
    roleItemVO.setRemark(role.getRemark());
    roleItemVO.setFixed(role.getFixed());
    roleItemVO.setCreateBy(role.getCreateBy());
    roleItemVO.setCreateAt(role.getCreateAt());
    roleItemVO.setUpdateBy(role.getUpdateBy());
    roleItemVO.setUpdateAt(role.getUpdateAt());
    return roleItemVO;
  }

  public static List<RoleVO> createFrom( List<Role> roles ){

    if( CollectionUtils.isEmpty(roles) ){
      return Collections.emptyList();
    }

    List<RoleVO> itemVOs = new ArrayList<>(roles.size());

    RoleVO itemVO;
    for(Role role : roles){
      itemVO = RoleVO.createFrom(role);
      itemVOs.add(itemVO);
    }

    return itemVOs;
  }

}
